package com.liuhuanss.idCard.pojo.dto;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class IdCardRecognitionResponse {
    private Header header;
    private String plainText; // 解码后的文本
    private String rawText;   // 原始的Base64编码文本

    // 构造方法
    public IdCardRecognitionResponse(ResponseData responseData) {
        if (responseData != null) {
            this.header = responseData.getHeader();
            if (responseData.getPayload() != null &&
                    responseData.getPayload().getResult() != null) {

                this.rawText = responseData.getPayload().getResult().getText();
                // 自动解码Base64
                if (this.rawText != null) {
                    this.plainText = new String(
                            Base64.getDecoder().decode(this.rawText),
                            StandardCharsets.UTF_8
                    );
                }
            }
        }
    }

    // Getters
    public Header getHeader() { return header; }
    public String getPlainText() { return plainText; }
    public String getRawText() { return rawText; }
}
